# -*- coding: utf-8 -*-
# @Author : Yuan
from rest_framework.generics import ListAPIView, RetrieveAPIView, GenericAPIView
from rest_framework.mixins import RetrieveModelMixin
from rest_framework.viewsets import ModelViewSet

from apps.goods.models import SPU, Brand, GoodsCategory
from apps.meiduo_admin.serializers.spu import SPUModelSerializer, BrandModelSerializer, GoodsCategoryModelSerializer
from apps.meiduo_admin.utils import PageNum


class SPUModelViewSet(ModelViewSet):
    queryset = SPU.objects.all()
    serializer_class = SPUModelSerializer
    pagination_class = PageNum


class BrandListAPIView(ListAPIView):
    queryset = Brand.objects.all()
    serializer_class = BrandModelSerializer


class GoodsCategoryListAPIView(ListAPIView):
    # queryset = GoodsCategory.objects.filter(parent=None)
    serializer_class = GoodsCategoryModelSerializer

    def get_queryset(self):
        parent_id = self.kwargs.get('parent_id')
        if parent_id:
            return GoodsCategory.objects.filter(parent_id=parent_id)
        return GoodsCategory.objects.filter(parent=None)




